<?
include_once 'include/processes.php';
$Login_Process = new Login_Process;
$Login_Process->check_status($_SERVER['SCRIPT_NAME']);
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en" xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Crash Report</title>
<link href="include/style.css" rel="stylesheet" type="text/css">
</head>

<body>

<?php 

if ($_GET['crash_addr']) {
	$addrStr = $_GET['crash_addr'];

	$conn = mysql_connect(DBHOST, DBUSER, DBPASS);
	if (!$conn) {
		echo "<p>DB error:".mysql_error."</p>";
		return;
	}
	if (!mysql_select_db(DBNAME, $conn)) {
		echo "<p>DB error:".mysql_error."</p>";
		return;
	}

	// first the caddr.id for the addrStr
	$queryStr = "SELECT id FROM caddr WHERE address = '$addrStr'";
	$result = mysql_query($queryStr);
	if (!$result) {
		echo "<p>Invalid crash address:".$addrStr."</p>";
		return;
	}
	$row = mysql_fetch_assoc($result);
	if (!row) {
		echo "<p>Invalid crash address:".$addrStr."</p>";
		return;
	}

	$cid = $row['id'];

	$queryStr = "SELECT co.date, (select u.username from users u where u.userid = co.user_id) as poster, co.content_text from comments co where co.caddr_id = $cid ORDER BY co.date DESC";

	$result = mysql_query($queryStr);
	if (!$result) {
		echo "<p>Failed to retrieve comments.</p>";
		return;
	}
	
	echo '<div class="center">';
	echo '<h1>Showing QA comments for crash '.$addrStr.'</h1>';
	echo '<h2>------------------------</h2>';
	while ($row = mysql_fetch_assoc($result)) {
		$postDate = $row['date'];
		$posterName = $row['poster'];
		$commentText = $row['content_text'];
		echo "<p>$posterName [$postDate]</p>";
		echo '<table width="400"><td>'.$commentText.'</td></table>';
		echo '<p>===========================================</p>';
	}
	echo '</div>';

	echo '<div class="center">';
	echo '<form enctype="multipart/form-data" action="add_comment.php?crash_addr='.$addrStr.'" method="post">';
	echo '<textarea name="comment_text" cols=40 rows=7></textarea><br />';
	echo '<input type="submit" value="Add Comment" />';
	echo '</form>';
	echo '</div>';

} else {
	echo "<p>잘못된 페이지 요청입니다.</p>";
}

?>

<div class="center">
<p>-----------------------------------</p>
</div>

<div class="center">
<a href="main.php">Back to main</a> | <a href="qa_report.php">Crash Report</a> | <a href="view_dumps.php">View Dumps</a>
</div>

</body>
</html>

